package com.hnqcgczy.supplier.service.impl;

import com.hnqcgczy.supplier.dao.ContactsDao;
import com.hnqcgczy.supplier.dao.impl.ContactsDaoImpl;
import com.hnqcgczy.supplier.db.MyTransaction;
import com.hnqcgczy.supplier.service.ContactsService;
import com.hnqcgczy.supplier.vo.Contacts;

import java.sql.SQLException;
import java.util.List;

public class ContactsServiceImpl implements ContactsService {
    private MyTransaction myTransaction = new MyTransaction(true);
    private ContactsDao contactsDao = new ContactsDaoImpl(myTransaction);

    @Override
    public boolean add(Contacts contacts) throws SQLException {
        return contactsDao.add(contacts) > 0;
    }

    @Override
    public boolean update(Contacts contacts) throws SQLException {
        return contactsDao.update(contacts) > 0;
    }

    @Override
    public boolean delete(Integer contactsId) throws SQLException {
        return contactsDao.delete(contactsId) > 0;
    }

    @Override
    public Contacts findOne(Integer contactsId) throws SQLException {
        return contactsDao.findOne(contactsId);
    }

    @Override
    public List<Contacts> findByLike(Contacts contacts, int pageNow, int pageSize) throws SQLException {

        int start =pageNow>=1? (pageNow - 1) * pageSize:pageNow*pageSize;

        return contactsDao.findByLike(contacts, start, pageSize);
    }

    @Override
    public int totals(Contacts contacts) throws SQLException {
        return contactsDao.totals(contacts);
    }
}
